package com.nervenets.template.service.impl;

import com.nervenets.general.service.impl.BaseServiceImpl;
import com.nervenets.template.hibernate.dao.AddressDao;
import com.nervenets.template.hibernate.domain.common.Address;
import com.nervenets.template.service.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressServiceImpl extends BaseServiceImpl<Address, AddressDao> implements AddressService {

    @Override
    public List<Address> findAllAddress(long userId) {
        return dao.findAllByUserIdAndDeletedOrderByDefDesc(userId, 0);
    }

    @Override
    @Transactional
    public void updateOtherAddressDefToFalse(long userId, Address def) {
        dao.updateAllAddressDefToFalse(userId);
        dao.updateAddressDefStatus(true, def.getId());
    }
}
